//
//  timerobj.m
//  yumeigui
//
//  Created by 孔令国 on 2017/6/17.
//  Copyright © 2017年 深圳研冠科技有限公司. All rights reserved.
//

#import "Timerobj.h"
@interface Timerobjs : NSObject{
    
}
@property(nonatomic) MyFuncPtr fpNotify;
@property(nonatomic) int timevalue;
@property(nonatomic) int value;
@property(nonatomic) id objclass;
@end
@implementation Timerobjs{
}
@synthesize fpNotify;
@synthesize timevalue;
@synthesize value;
@synthesize objclass;
@end
@implementation Timerobj{
    Timerobjs *timerobjs[max_timer_id];
}

-(void)starttimer{
    NSTimer *Timer = [NSTimer scheduledTimerWithTimeInterval:0.01f target:self selector:@selector(refreshStart) userInfo:nil repeats:YES];
    [Timer fire];//启动定时器
    
    for (int i=0; i<max_timer_id; i++) {
        timerobjs[i]=[Timerobjs alloc];
        timerobjs[i].timevalue=0;
        
    }
}
-(void)refreshStart{
    for (int i=0; i<max_timer_id; i++) {
        if (timerobjs[i].timevalue>1) {
            timerobjs[i].timevalue--;
        }else if(timerobjs[i].timevalue==1){
            timerobjs[i].timevalue=0;
            if (timerobjs[i].fpNotify!=nil) {
                timerobjs[i].fpNotify(timerobjs[i].value,timerobjs[i].objclass);
            }
            
            
        }
    }
}
-(void)myTimerStart:(int)timerid timevalue:(int)timevalue myFuncPtr:(MyFuncPtr)myFuncPtr value:(int)value objclass:(id)objclass{
    timerobjs[timerid].timevalue=timevalue;
    timerobjs[timerid].fpNotify=myFuncPtr;
    timerobjs[timerid].value=value;
    timerobjs[timerid].objclass=objclass;
}

@end

